--- <action itemid="2324" event="script" value="flying broom.lua" allowfaruse="1"/>
--- Flying broom maked by Kronos aka Hellboy ---

local maxRage = 4

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if not isPremium(cid) then
		doPlayerSendCancel(cid, "Only premium players are able to using flying broom.")
		return doSendMagicEffect(fromPosition, CONST_ME_POFF)
	end

	if(toPosition.x == CONTAINER_POSITION) then
		doPlayerSendCancel(cid, "You can't use it inside container.")
		return doSendMagicEffect(fromPosition, CONST_ME_POFF)
	end

	local getItemFromToPositon = getThingFromPos({x=toPosition.x, y=toPosition.y, z=toPosition.z})
 
	if hasProperty(getItemFromToPositon.uid, CONST_PROP_BLOCKPATHFIND) or hasProperty(getItemFromToPositon.uid, CONST_PROP_BLOCKSOLID) then
		doPlayerSendCancel(cid, "You can't do it.")
		return false
	end
	
	if getTileHouseInfo(toPosition) ~= 0 then
		doPlayerSendCancel(cid, "You can't do it.")
		doSendMagicEffect(fromPosition, 2)
		return true
	end
	
	if getDistanceBetween(getCreaturePosition(cid), toPosition) == 0 then
		return false
	end
	
	if maxRage ~= nil then
		if maxRage < getDistanceBetween(getCreaturePosition(cid), toPosition) then
			doPlayerSendCancel(cid, "Out of rage.")
			return true
		end
	end
	
	doTeleportThing(cid, toPosition)
	doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
	doSendMagicEffect(fromPosition, CONST_ME_POFF)
	doCreatureSay(cid, "Ziuuuuuu!", TALKTYPE_ORANGE_1)
	doTransformItem(item.uid, 2551)
	return true
	
end
